package com.jxm.hutools;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil;
import org.junit.Test;
import org.junit.Assert;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023-12-18 16:53
 * @Version: 1.0
 */
public class IdcardUtilTest {

    @Test
    public void test1(){
        String ID_18 = "321083197812162119";
        String ID_15 = "150102880730303";

        //是否有效
        boolean valid = IdcardUtil.isValidCard(ID_18);
        boolean valid15 = IdcardUtil.isValidCard(ID_15);
//        System.out.println(valid);
//        System.out.println(valid15);

        //转换
        String convert15To18 = IdcardUtil.convert15To18(ID_15);
        Assert.assertEquals(convert15To18, "150102198807303035");

        //年龄
        DateTime date = DateUtil.parse("2017-04-10");

        int age = IdcardUtil.getAgeByIdCard(ID_18, date);
        Assert.assertEquals(age, 38);

        int age2 = IdcardUtil.getAgeByIdCard(ID_15, date);
        Assert.assertEquals(age2, 28);

        //生日
        String birth = IdcardUtil.getBirthByIdCard(ID_18);
        Assert.assertEquals(birth, "19781216");

        String birth2 = IdcardUtil.getBirthByIdCard(ID_15);
        Assert.assertEquals(birth2, "19880730");

        //省份
        String province = IdcardUtil.getProvinceByIdCard(ID_18);
        Assert.assertEquals(province, "江苏");

        String province2 = IdcardUtil.getProvinceByIdCard(ID_15);
        Assert.assertEquals(province2, "内蒙古");
    }

    @Test
    public void test2(){
        String ID_18_test = "522631199310124714";
        //是否有效
        System.out.println(IdcardUtil.isValidCard(ID_18_test));
        System.out.println(IdcardUtil.getProvinceByIdCard(ID_18_test));
        System.out.println(IdcardUtil.getCityCodeByIdCard(ID_18_test));
        System.out.println(IdcardUtil.getDistrictCodeByIdCard(ID_18_test));
        System.out.println(IdcardUtil.getIdcardInfo(ID_18_test));
        System.out.println(IdcardUtil.getBirth(ID_18_test));
        System.out.println(IdcardUtil.getBirthByIdCard(ID_18_test));
        System.out.println(IdcardUtil.getBirthDate(ID_18_test));

    }
}
